package com.xidian.zhiancloud.controller.equipFacility.ohManager;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xidian.zhiancloud.controller.base.BaseController;
import com.xidian.zhiancloud.dto.ResultDTO;
import com.xidian.zhiancloud.enums.GeneralResponseEnums;
import com.xidian.zhiancloud.model.OhRegister;
import com.xidian.zhiancloud.qo.equipFacility.OhPlanDraftQO;
import com.xidian.zhiancloud.qo.equipFacility.OhPlanExecuteQO;
import com.xidian.zhiancloud.qo.equipFacility.OhPlanRegisterQO;
import com.xidian.zhiancloud.service.equipFacility.OhPlanExecuteService;
import com.xidian.zhiancloud.vo.equipFacility.EqFacAndRegisterVO;
import com.xidian.zhiancloud.vo.equipFacility.OhPlanDraftVO;
import com.xidian.zhiancloud.vo.equipFacility.OhPlanEqFacMngVO;
import com.xidian.zhiancloud.vo.equipFacility.OhPlanExcuteVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName OhPlanExecuteController
 * @Description 检修计划执行
 * @Author Halo
 **/
@RestController
@RequestMapping("/OhPlanExecute")
public class OhPlanExecuteController extends BaseController {

    @Autowired
    private OhPlanExecuteService ohPlanExecuteService;

    /**
     * 列表查询
     * @param ohPlanDraftQO
     * @return  返回列表
     */
    @GetMapping("/getList")
    public ResultDTO<IPage<OhPlanDraftVO>> getListByQO(OhPlanDraftQO ohPlanDraftQO) {
        if (ohPlanDraftQO.getCurrent()== null || ohPlanDraftQO.getSize() == null) {
            return ResultDTO.errorOf(GeneralResponseEnums.REQUEST_ERROR);
        }
        ohPlanDraftQO.setCompanyId(getSessionUserCompanyId());
        ohPlanDraftQO.setUserId(getSessionUserid());
        return ResultDTO.successOf(ohPlanExecuteService.getListByQO(ohPlanDraftQO), GeneralResponseEnums.SUCCESS);
    }

    /**
     * 检修计划执行  --  提交
     * @param id
     * @return
     */
    @PostMapping("/submit")
    public ResultDTO<Boolean> submit(Long id){
        return ResultDTO.successOf(ohPlanExecuteService.submit(id,getSessionUserid()),GeneralResponseEnums.SUCCESS);
    }

    /**
     * 检修计划执行 -- 查看
     * @param ohPlanExecuteQO 请求参数
     * @return
     */
    @GetMapping("/getListById")
    public ResultDTO<IPage<OhPlanExcuteVO>> getListById(OhPlanExecuteQO ohPlanExecuteQO){
        if (ohPlanExecuteQO.getCurrent()== null || ohPlanExecuteQO.getSize() == null) {
            return ResultDTO.errorOf(GeneralResponseEnums.REQUEST_ERROR);
        }
        return ResultDTO.successOf(ohPlanExecuteService.getListById(ohPlanExecuteQO,getSessionUserid()),GeneralResponseEnums.SUCCESS);
    }

    /**
     * 查看设备信息和检修项
     * @param eqFacMngId  设备id
     * @param planId 检修计划id
     * @return
     */
    @GetMapping("/getEqFacMngMsgById")
    public ResultDTO<OhPlanEqFacMngVO> getEqFacMngMsgById(Long eqFacMngId,Long planId){
        return ResultDTO.successOf(ohPlanExecuteService.getEqFacMngMsgById(eqFacMngId,planId),GeneralResponseEnums.SUCCESS);
    }

    /**
     * 检修计划执行---执行（检修）
     * @param ohPlanRegisterQO
     * @return
     */
    @PostMapping("/execute")
    public ResultDTO<Boolean> execute(OhPlanRegisterQO ohPlanRegisterQO){
        ohPlanRegisterQO.setCompanyId(getSessionUserCompanyId());
        return ResultDTO.successOf(ohPlanExecuteService.repair(getSessionUserid(),ohPlanRegisterQO),GeneralResponseEnums.SUCCESS);
    }

    /**
     * 检修项检修之后--【编辑】可修改
     * @param ohRegister
     * @return
     */
    @PostMapping("/update")
    public ResultDTO<Boolean> updateById(OhRegister ohRegister){
        ohRegister.setCreator(null);
        ohRegister.setCompanyId(null);
        ohRegister.setOhTime(null);
        ohRegister.setProtectStep(null);
        ohRegister.setOhTypeId(null);
        ohRegister.setIsSubmitted(null);
        ohRegister.setEqFacId(null);
        ohRegister.setRepairUsersId(null);
        ohRegister.setCreateTime(null);
        return ResultDTO.successOf(ohPlanExecuteService.updateById(ohRegister),GeneralResponseEnums.SUCCESS);
    }

    /**
     * 检修计划执行--执行--查看
     * @param ohPlanRegisterQO 传入检修计划id和设备设施id
     * @return
     */
    @GetMapping("/lookOver")
    public ResultDTO<EqFacAndRegisterVO> lookOver(OhPlanRegisterQO ohPlanRegisterQO){
        return ResultDTO.successOf(ohPlanExecuteService.lookOver(ohPlanRegisterQO),GeneralResponseEnums.SUCCESS);
    }

    /**
     * 检修之后查看检修项检修登记信息
     * @param ohPlanRegisterQO
     * @return
     */
    @GetMapping("/getRegister")
    public ResultDTO<OhRegister> getRegister(OhPlanRegisterQO ohPlanRegisterQO){
        return ResultDTO.successOf(ohPlanExecuteService.getRegister(ohPlanRegisterQO),GeneralResponseEnums.SUCCESS);
    }
}
